// 引入api接口函数
import {
	reqGetReadBannerDatas,
	reqGetReadListDatas
} from '@/api'
const state = {
	readBannerDatas: [], //轮播图数据
	firstReadListDatas: [], //一级频道数据
	secondReadListDatas: [], //二级频道数据
	thirdReadListDatas: [], //三级频道数据
}
const mutations = {
	UPDATE_READ_BANNER_DATAS(state, readBannerDatas) {
		state.readBannerDatas = readBannerDatas
	},
	UPDATE_FIRST_READ_LIST_DATAS(state, firstReadListDatas){
		state.firstReadListDatas = firstReadListDatas
	},
	UPDATE_SECOND_READ_LIST_DATAS(state, secondReadListDatas){
		state.secondReadListDatas = secondReadListDatas
	},
	UPDATE_THIRD_READ_LIST_DATAS(state, thirdReadListDatas){
		state.thirdReadListDatas = thirdReadListDatas
	}
}
const actions = {
	async updateReadBannerDatas({commit}) {
		let result = await reqGetReadBannerDatas()
		commit('UPDATE_READ_BANNER_DATAS', result)
	},
	async updateReadListDatas({commit},{firstId,secondId}) {
		if (firstId === undefined && secondId === undefined) {
			let result = await reqGetReadListDatas()
			commit('UPDATE_FIRST_READ_LIST_DATAS', result)
			return
		}
		if (firstId && secondId === undefined) {
			let result = await reqGetReadListDatas(firstId)
			commit('UPDATE_SECOND_READ_LIST_DATAS', result)
			return
		}
		if (firstId && secondId) {
			let result = await reqGetReadListDatas(firstId, secondId)
			commit('UPDATE_THIRD_READ_LIST_DATAS', result)
			return
		}
	},
}
const getters = {

}
export default {
	state,
	mutations,
	actions,
	getters
}